package org.batatasframework.support.database.parameters;

import java.sql.PreparedStatement;

import cn.bonoon.kernel.util.StringHelper;

public class NumberParamenter extends AbstractQueryParameter<Long>{

	public NumberParamenter(int index, Long value){
		super(index, value);
	}
	
	public static final Long valueOf(Object value){
		if(value instanceof Number){
			return ((Number) value).longValue();
		}else if(value instanceof Boolean){
			return ((Boolean)value).booleanValue() ? 1L : 0L;
		}else{
			return StringHelper.toLong(value.toString());
		}
	}
	
	public NumberParamenter(int index, Object value){
		super(index, valueOf(value));
	}
	
	public NumberParamenter(int index, String value){
		super(index, Long.parseLong(value));
	}
	
	@Override
	public void set(PreparedStatement statement) throws Exception {
		statement.setLong(index, value);
	}

}
